from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain_community.llms import Ollama
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_community.document_loaders import TextLoader

loader = TextLoader("../demo.txt", encoding="utf-8")
docs = loader.load()
print(docs)


llm = Ollama(model="qwen2.5")
prompt = ChatPromptTemplate.from_template("""仅根据提供的上下文回答以下问题:

<context>
{context}
</context>

Question: {input}""")

document_chain = prompt | llm


print(document_chain.invoke({
    "input": "普通话证书算加分项吗",
    "context": docs
}))
